package com.lin.sms.page;

import java.util.List;

import com.lin.sms.domain.Score;

public class PageResult {
    // 结果集
    private List<Score> listData;
    // 总条数
    private Integer totalCount;
    // 总页数
    private Integer totalPage;
    // 当前页
    private Integer currentPage;
    // 上一页
    private Integer prePage;
    // 下一页
    private Integer nextPage;
    // 首页
    private Integer beginPage;
    // 页面大小
    private Integer pageSize;
    //要显示的索引数
    private Integer indexCount;
    //开始索引的页面
    private Integer beginIndex;
    //结束索引的页面
    private Integer endIndex;
    
   

    public PageResult() {}//无参构造器,,对象注入用

    public PageResult(List<Score> listData, Integer totalCount, Integer currentPage, Integer pageSize) {
        this.listData = listData;
        this.totalCount = totalCount;
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.indexCount =5;//默认是5条索引,提供一个set方法,供外部设置.
        this.beginPage = 1;
        // 计算总页数
        this.totalPage = this.totalCount % this.pageSize == 0 ? this.totalCount / this.pageSize
            : this.totalCount / this.pageSize + 1;
        // 计算当前页
        //this.currentPage = currentPage > totalPage? totalPage : currentPage;
        // 计算上一页
        this.prePage = this.currentPage > 1 ? this.currentPage - 1 : 1;
        // 计算下一页
        this.nextPage = this.currentPage < this.totalPage ? this.currentPage + 1 : this.totalPage;
        PageIndex pageIndex = new PageIndex(indexCount,currentPage,totalPage);
        this.beginIndex = pageIndex.getBeginIndex();
        this.endIndex = pageIndex.getEndIndex();
    }

   
    @Override
    public String toString() {
        return "PageResult [listData=" + listData + ", totalCount=" + totalCount + ", totalPage=" + totalPage
            + ", currentPage=" + currentPage + ", prePage=" + prePage + ", nextPage=" + nextPage + ", beginPage="
            + beginPage + ", pageSize=" + pageSize + ", indexCount=" + indexCount + ", beginIndex=" + beginIndex
            + ", endIndex=" + endIndex + "]";
    }

    public void setIndexCount(Integer indexCount) {
        this.indexCount = indexCount;
    }

    public List<Score> getListData() {
        return listData;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public Integer getPrePage() {
        return prePage;
    }

    public Integer getNextPage() {
        return nextPage;
    }

    public Integer getBeginPage() {
        return beginPage;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public Integer getIndexCount() {
        return indexCount;
    }

    public Integer getBeginIndex() {
        return beginIndex;
    }

    public Integer getEndIndex() {
        return endIndex;
    }
}
